﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common;

namespace Web.Views.SystemLogin
{
    public partial class ModifyPassword : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.txtLoginName.Text = this.CurrentUser.Login_ID;
            this.txtLoginName.Enabled = false;
        }

        protected void btnEditPasssword_Click(object sender, EventArgs e)
        {
            //检查输入的密码和确认密码
            if (this.txtNewPassword.Text != this.txtComfrimPassword.Text)
            {
                Alert("确认密码和输入的新密码不一致!");
                this.txtComfrimPassword.Focus();
                return;
            }
            //检查用户名密码
            bool isOk = false;
            string loginName = this.txtLoginName.Text;
            string password = EncryptDecrypt.EncryptPassword(this.txtPassword.Text.Trim(), "MD5");
            isOk = SystemLoginComponent.ValiadateUserPWD(loginName, password, "UserPwd");
            //执行数据库更改
            if (isOk)
            {
               password = EncryptDecrypt.EncryptPassword(this.txtNewPassword.Text.Trim(), "MD5");
               isOk= SystemLoginComponent.UpdateUserPassword(loginName,password);
               if (!isOk)
               {
                   Alert("修改密码失败，请重试!");
               }
               else
               {
                   Alert("修改密码成功！");
               }
            }
            else
            {
                Alert("你的用户名或密码输入不正确，请检查输入的用户名和密码!");
            }
        }
    }
}